# Contributor: David Demelier <markand@malikania.fr>
# Maintainer: David Demelier <markand@malikania.fr>
pkgname=libretro-ppsspp
pkgver=0_git20210516
pkgrel=3
_vers="v1.11.3-672-gf1bf596f5"
_commit="f1bf596f5c6301a9f757b18b7823fd9f34f235ef"
_commit_armips="7885552b208493a6a0f21663770c446c3ba65576"
_commit_ppsspp_lang="3bf6b18eb0ae68861fbfbb7b43cd764771ca42a9"
_commit_rapidjson="73063f5002612c6bf64fe24f851cd5cc0d83eef9"
_commit_spirv_cross="9acb9ec31f5a8ef80ea6b994bb77be787b08d3d1"
pkgdesc="libretro core for ppsspp"
url="https://github.com/hrydgard/ppsspp"
arch="all !s390x"
license="GPL-2.0-only"
makedepends="cmake
	ffmpeg4-dev
	glslang-dev
	glslang-static
	libpng-dev
	libzip-dev
	mesa-dev
	miniupnpc-dev
	ninja
	python3
	snappy-dev
	zlib-dev
	zstd-dev"
source="$pkgname-$_commit.tar.gz::https://github.com/hrydgard/ppsspp/archive/$_commit.tar.gz
	$pkgname-armips-$_commit_armips.tar.gz::https://github.com/Kingcom/armips/archive/$_commit_armips.tar.gz
	$pkgname-ppsspp-lang-$_commit_ppsspp_lang.tar.gz::https://github.com/hrydgard/ppsspp-lang/archive/$_commit_ppsspp_lang.tar.gz
	$pkgname-rapidjson-$_commit_rapidjson.tar.gz::https://github.com/Tencent/rapidjson/archive/$_commit_rapidjson.tar.gz
	$pkgname-spirv-cross-$_commit_spirv_cross.tar.gz::https://github.com/KhronosGroup/spirv-cross/archive/$_commit_spirv_cross.tar.gz
	patch-unbundle.patch
	patch-disable-git-version.patch
	"
builddir="$srcdir/ppsspp-$_commit"
options="!check" # No tests

prepare() {
	default_prepare
	rm -rf ext/armips && mv "$srcdir"/armips-$_commit_armips ext/armips
	rm -rf ext/rapidjson && mv "$srcdir"/rapidjson-$_commit_rapidjson ext/rapidjson
	rm -rf ext/SPIRV-Cross && mv "$srcdir"/SPIRV-Cross-$_commit_spirv_cross ext/SPIRV-Cross
	rm -rf assets/lang && mv "$srcdir"/ppsspp-lang-$_commit_ppsspp_lang assets/lang
	sed -i -e "s,@VERSION@,$_vers," git-version.cmake
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_SKIP_RPATH=On \
		-DOpenGL_GL_PREFERENCE=GLVND \
		-DHEADLESS=Off \
		-DLIBRETRO=On \
		-DMOBILE_DEVICE=Off \
		-DSIMULATOR=Off \
		-DUNITTEST=Off \
		-DUSE_SYSTEM_LIBZIP=On \
		-DUSE_SYSTEM_SNAPPY=On \
		-DUSE_SYSTEM_ZSTD=On \
		-DUSE_SYSTEM_FFMPEG=On \
		-DUSING_QT_UI=Off \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

package() {
	install -Dm644 build/lib/ppsspp_libretro.so "$pkgdir"/usr/lib/libretro/ppsspp_libretro.so
}

sha512sums="
7bc671c8da5e7c77a2609022bbbbecff4b21d65a4c32e4497814b42235a4a870c1aafc66abeb0b875ba7ed42873cdc824f901adb7d090cb583e657ba9b06c641  libretro-ppsspp-f1bf596f5c6301a9f757b18b7823fd9f34f235ef.tar.gz
2a94e2c7b7280c00a39c8fc92d81ed15fc4b3270a124ef882e3cd8878db6ec827aefa06b0e646a60916636a95e4ebfa886e9878ba70c6bcfcd048def457368be  libretro-ppsspp-armips-7885552b208493a6a0f21663770c446c3ba65576.tar.gz
691cb38c65ca20700dc5b91c0dc02eec1839f153e042c87f8f4fd480e44c823c0ece9f4752f5e597f2aa4b5cfb22aaf49d76ff990eb2dd5231cc4065dd62566d  libretro-ppsspp-ppsspp-lang-3bf6b18eb0ae68861fbfbb7b43cd764771ca42a9.tar.gz
3472e129e710bf5343b8b27a61581a1480c8096493e466440b62702d8b5353745d561931f72b5405a736ad92525be3843ea1cf4b5ea5839721cc6d6b358f19bc  libretro-ppsspp-rapidjson-73063f5002612c6bf64fe24f851cd5cc0d83eef9.tar.gz
be77131814691dfbe65de3a2d3ea65de98c7169824997056637bbce39485327ff0f64e7eed8588237615948824e1f9dff1d083472b8cbccd3748a52379411e4e  libretro-ppsspp-spirv-cross-9acb9ec31f5a8ef80ea6b994bb77be787b08d3d1.tar.gz
bce348cba279e746b77d3e75bddbdbdbbdb6643385e7a5f9d3f1dcb22a1fd7708acf16cc5e7acc8756e9ab9da9caeaef1a140d245df141acb23c07f9c23080e8  patch-unbundle.patch
859901bd42934b52f82c28c1f5f3b43277f54d79d58c035c063e615de3a5959a373ef8d9c0199ed1326bbd64b7b12f4582957851d57d2dd66b5ba8488bbb8734  patch-disable-git-version.patch
"
